package ca.seia.comp6521.a1.io;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DataFileReader {

	// I am using Collections like Queues and LinkedList and SortedMap
	// Hence Please Use Integer in Reading and Writing

	String absolutefilePath;
	BufferedReader reader;
	int nbrOfIntegersRead = 0;
	boolean isFirstRead = true;

	public DataFileReader(String absolutefilePath) throws FileNotFoundException {
		this.absolutefilePath = absolutefilePath;
		this.reader = new BufferedReader(new FileReader(this.absolutefilePath));
	}

//	public boolean readNextIntegers(int numberOfIntegers,
//			List<Integer> integers) {
//
//		// int[] integers = new int[numberOfIntegers];
//		int integersCount = 0;
//		String line;
//		boolean isEndOfFileReached = false;
//
//		try {
//			while (integersCount < numberOfIntegers) {
//				line = reader.readLine();
//
//				if (line != null) {
//					// integers[integersCount] = Integer.parseInt(line);
//					integers.add(Integer.parseInt(line));
//					integersCount++;
//				} else {
//					isEndOfFileReached = true;
//					break;
//				}
//			}
//
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//
//		return isEndOfFileReached;
//	}
	
	public boolean readNextIntegers(int numberOfIntegers,List<Integer> integers) {
		
		int integersCount = 0;
		String line;
		boolean isEndOfFileReached = false;

		try {
			while (integersCount < numberOfIntegers) {
				line = reader.readLine();

				if (line != null) {
					integers.add(Integer.parseInt(line));
					integersCount++;
				} else {
					isEndOfFileReached = true;
					break;
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return isEndOfFileReached;
	}

	public String getAbsolutefilePath() {
		return absolutefilePath;
	}

	public void setAbsolutefilePath(String absolutefilePath) {
		this.absolutefilePath = absolutefilePath;
	}

	public BufferedReader getReader() {
		return reader;
	}

	public void setReader(BufferedReader reader) {
		this.reader = reader;
	}

}
